package com.unit6;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author 李琦 on 2021/8/16.
 * @version java version "16.0.1" 2021-04-20
 * 数据库的连接
 *
 */
public class test1 {
    public static void main(String[] args) {

        Connection conn=null;
        String address = "jdbc:mysql://localhost:3306/data1?useSSL=false&serverTimezone=UTC";
        String dataBaseName="root";
        String dataBasePwd="123456";
        try {
            //加载jdbc驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            //连接数据库
            conn= DriverManager.getConnection(address,dataBaseName,dataBasePwd);
            System.out.println("连接成功!");
            //处理数据

        } catch (Exception e) {
            System.out.println("连接失败!");
            e.printStackTrace();
        } finally{
            try {
                conn.close();//关闭连接资源
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}
